package com.bianmaba.jobs.supports;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.quartz.JobDataMap;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@ToString
public class CollectionRequest {
    private String projectId;
    private String taskId;
    private String taskInstanceId;
    private String description;
    private Map<String, String> collectionParameters = new HashMap<>();

    public CollectionRequest(JobDataMap jobDataMap) {
        this.projectId = jobDataMap.getString(JobParameter.PROJECT_ID.getName());
        this.taskId = jobDataMap.getString(JobParameter.TASK_ID.getName());
        this.taskInstanceId = jobDataMap.getString(JobParameter.TASK_INSTANCE_ID.getName());
        List<Map<String, String>> maps = (List<Map<String, String>>) jobDataMap.get(JobParameter.COLLECTION_PARAMETERS.getName());
        for (Map<String, String> map : maps) {
            collectionParameters.put(map.get("name"), map.getOrDefault("value", null));
        }
        this.description = jobDataMap.getString(JobParameter.DESCRIPTION.getName());
    }
}
